package com.jctrip.hotel.source.xxl.wehotel.thread;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.wehotel.WeHotelTaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;


/**
 * @Author: zxy
 * @CreateTime: 2023-10-24 20:02
 * @Description:
 */
@Slf4j
public class SyncWehotelPicTaskThread implements Runnable {
    private final String appId;

    private final String key;

    public SyncWehotelPicTaskThread(String appId, String key) {
        this.appId = appId;
        this.key = key;
    }

    @Override
    public void run() {
        WeHotelTaskService weHotelTaskService = BeanContext.getApplicationContext().getBean(WeHotelTaskService.class);
        RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);

        while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_WEHOTEL_PIC_LIST) > 0) {
            try {
                String innId = (String) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_WEHOTEL_PIC_LIST);
                if (StringUtils.isBlank(innId)) {
                    continue;
                }
                weHotelTaskService.syncWehotelPic(appId, key, innId);
            } catch (Exception e) {
                log.error("SyncWehotelRatesTaskThread error", e);
            }
        }
    }
}
